package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

/**
 * @Author: Learner
 * @Version: 1.0
 * 护理项目
 */
@Api(tags = "护理项目")
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {


    @Autowired
    private NursingProjectService nursingprojectService;

    @GetMapping
    @ApiOperation("分页查询护理项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理项目名称", required = false, dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "status", value = "状态", required = false, dataType = "Integer")
    })
    public ResponseResult<PageResponse<NursingProjectVo>> findByPage(String name,
                                                                     @RequestParam(defaultValue = "1") Integer pageNum,
                                                                     @RequestParam(defaultValue = "10") Integer pageSize,
                                                                     Integer status) {
        PageResponse<NursingProjectVo> byPage = nursingprojectService.findByPage(name, pageNum, pageSize, status);
        return success(byPage);
    }

    @PostMapping
    @ApiOperation(value = "新增护理项目", notes = "传入护理项目信息")

    public ResponseResult<Integer> addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        Integer integer = nursingprojectService.addNursingProject(nursingProjectDto);
        return toAjax(integer);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询回显")
    public  ResponseResult<NursingProjectVo> findById(@ApiParam("主键id") @PathVariable long id){
        NursingProjectVo nursingProjectVo=nursingprojectService.findById(id);
        return success(nursingProjectVo);

    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult updateNursing(@RequestBody  NursingProjectDto nursingProjectDto){
        nursingprojectService.updateNursing(nursingProjectDto);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理项目")

    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理项目ID", required = true) @PathVariable Long id,
            @ApiParam(value = "护理项目状态", required = true) @PathVariable Integer status) {
        nursingprojectService.enableOrDisable(id, status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delNursing(@ApiParam(value = "护理项目ID",required = true) @PathVariable long id){
        nursingprojectService.delNursing(id);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> allNursing(){
        List<NursingProjectVo> nursingProjectVo=nursingprojectService.allNursing();
        return success(nursingProjectVo);
    }
}
